package com.jian.mall.web;

import com.jian.mall.service.ElasticsearchService;
import com.jian.mall.vo.SearchConditionVo;
import com.jian.mall.vo.SearchResult;
import org.elasticsearch.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/search")
public class IndexPageController {

    @Autowired
    private ElasticsearchService elasticsearchService;

    @GetMapping({"/", "/index.html", "search.html"})
    public String indexPage(Model model, SearchConditionVo conditionVo) {
        SearchResult result = elasticsearchService.byConditionVoSearch(conditionVo);
        model.addAttribute("result",result);
        return "index";
    }

}
